#pragma once
#include "render_target.h"
#include "opengl.h"
#include <map>

namespace krryn{
namespace view{ class renderer; } // TODO: remove
namespace system_imp{
	class render_target_opengl : public view::render_target{
	public:
		render_target_opengl(int a_Width, int a_Height);
		~render_target_opengl();

		virtual void attach(view::target_type a_Type, const std::string &a_Name);
		virtual void start_render();
		virtual void end_render();

		GLuint get_texture_id(const std::string &a_Name);
		virtual std::vector<std::string> get_attachment_names();
		class fbo_attachment;
	private:
		enum buffer_type{
			texture,
			buffer,
		};

		fbo_attachment *create_attachment(view::target_type a_Type, const std::string &a_Name);
		std::string get_fbo_error_string(GLenum status);

		std::map<std::string, fbo_attachment*> m_NameToAttachment;
		std::vector<fbo_attachment*> m_Attachments;
		GLuint m_FboId;
		int m_ColorAttachmentCount;
		bool m_HasDepthAttachment;
	};

}
}